import baseControl from '../../../../app/base/baseControl';
import { Quadtree, Rect } from '../../../../app/module/quadTree/quadTree';

let pos = { x: 0, y: 0 }

export default new class pageQuadtreeControl extends baseControl {
    private tree: Quadtree = null;

    initTree(width, height) {
        if (this.tree) this.tree.clear();

        this.tree = new Quadtree(
            new Rect(0, 0, width, height)
        );
    }

    insertRect(x: number, y: number, w: number, h: number, uuid?: string) {
        return this.tree.insert(new Rect(x, y, w, h, uuid));
    }

    refreshRect(uuid: string, x: number, y: number) {
        pos.x = x;
        pos.y = y;
        return this.tree.refresh(uuid, pos);
    }

    retrieveRects(uuid: string) {
        return this.tree.retrieve(uuid);
    }
}